﻿﻿﻿﻿﻿﻿require.config({
  urlArgs: "version=20170501",
  paths: {
    'jquery': '/js/packages/jquery-2.14-min',
    'bootstrap':'/bootstrap/js/bootstrap'
  },
  shim: {
    'bootstrap': {
      deps: ['jquery'],
      exports: 'bootstrap'
    }
  }
});





require(['jquery','bootstrap'], function ($) {

var chooseList = [];
block = true;
curr_num = 0;
picInfo = "";
date_set_20 = [];
var myDate = new Date();
curr_year = parseInt(myDate.getFullYear())-20;
for(var count=1;count<=20;count++) {
	date_set_20.push(curr_year+count);
}
var show_list = {
		'1001':0,
		'1002':0,
		'1003':0,
		'2001':0,
		'2002':0,
		'2003':0,
		'2004':0,
		'2005':0,
		'2006':0,
		'2007':0,
		'2008':0,
		'3001':0,
		'3002':0,
		'3003':0,
		'3004':0,
		'3005':0,
		'3006':0,
		'3007':0,
		'3008':0,
		'3009':0,
		'4001':0,
		'4002':0,
		'4003':0,
		'4004':0,
		'4005':0,
		'4006':0,
		'4007':0,
		'4008':0,
		'4009':0,
		'4010':0,
		'5001':0,
		'5002':0,
		'5003':0,
		'5004':0,
		'5005':0,
		'5006':0,
		'5007':0,
		'5008':0,
		'5009':0,
		'5010':0,
		'5011':0,
		'5012':0,
		'6001':0,
		'6002':0,
		'6003':0,
		'6004':0,
		'6005':0,
		'6006':0,
}
$('div.graph-select>input').on("change",function(argument) {
	var graph_id = $(this).attr('id').split('-')[2];
	if($(this).prop('checked')){
		chooseList.push(graph_id);
	}else {
		var index = chooseList.indexOf(graph_id);
		if (index > -1) {
			chooseList.splice(index, 1);
		}
	}
	
	fresh_des();
});
function fresh_des() {
	var select_div = document.getElementById("show-graph-select");
	select_div.innerHTML="";
	for(var e in chooseList) {
		var li = document.createElement("li");
		li.setAttribute("class", "list-selected");
		var spanId = document.createElement("span");
		spanId.setAttribute("class", "idx");
		spanId.innerHTML=Number(e)+1;
		id = "graph-name-"+chooseList[e];
		var spanDoc = document.createElement("span");
		spanDoc.innerHTML=$("#"+id).text();
		li.appendChild(spanId);
		li.appendChild(spanDoc);
		select_div.appendChild(li);
	}

};

$('#report-btn').click(function () {
	draw_all_pic();
});
 function draw_all_pic() {
	 document.getElementById("download-report").setAttribute("class","btn btn-primary disabled");
	 document.getElementById("show-bar").style.width="10%";
	 
	 $('#report-download').modal('show');
	 var all_div = document.getElementById("all-graphs");
	 all_div.innerHTML="";
	 for(var e in chooseList) {
		 id = "graph-hidden-"+chooseList[e];
		 curr_num = Number(e)+1;
		 $('#'+id).click();
	 }
 };
 function sleep(numberMillis) {
     var now = new Date();
     var exitTime = now.getTime() + numberMillis;
     while (true) {
         now = new Date();
         if (now.getTime() > exitTime)
             return;
     }
 }
  function make_pic(myChart,e) {
  	var base64Info = myChart.getDataURL();
	$.ajax({
	　　　　type: "post",
	　　　　data: {
	　　　　　　base64Info: base64Info,
	      	name:e
	　　　　},
	　　　　url: '/draw/pic',
	　　　　async: false,
	　　　　success: function(data) {
			var num = e/chooseList.length;
			num = (num)*100-10;
	　　　　　　document.getElementById("show-bar").style.width=num+"%";
	　　　　},
	　　　　error: function(err){
	　　　　　　console.log('图片保存失败');
	　　　　　　alert('图片保存失败');
	　　　　}
	　});
	if(e==chooseList.length) {
		setTimeout(function(){make_report();}
		, 5000);
	}
  }
  
  
  function make_report() {
	  $.ajax({
		　　　　type: "GET",
		　　　　url: '/make/report',
		　　　　async: false,
		     cache: false,
		　　　　success: function(data) {
		　　　　　　//active
		  		document.getElementById("show-bar").style.width=100+"%";
		  		document.getElementById("download-report").setAttribute("class","btn btn-primary");
		  		//"btn btn-primary disabled"
		　　　　},
		　　　　error: function(err){
		　　　　　　console.log('图片保存失败');
		　　　　　　alert('文件生成失败');
		　　　　}
		　});
  }
  function add_new_div(d) {
	var all_div = document.getElementById("all-graphs");
  	var new_div = document.createElement("div");
  	new_div.setAttribute("class", "show-graph");
  	var curr_id = 'content-graph-hidden'+d;
  	new_div.setAttribute("id", curr_id);
  	all_div.appendChild(new_div);
  	return curr_id;
  }
  
  
  function draw_graph(myChart,option) {
	  myChart.clear();
	option.toolbox= {}
	  
	  myChart.setOption(option);
  }
  
  function post_to_draw(myChart,f_graph_message,graph_id,d) {
	  $.ajax({
			type : 'POST',  
			url : '/graph/draw/option', 
			data : {
				'graph_message':JSON.stringify(f_graph_message), 
			},
	        contentType: "application/x-www-form-urlencoded",  
	        dataType : 'json',  
	        success : function(res) {
			    options = eval('(' + res.data + ')');
			    all_options = options.value;
			    draw_graph(myChart,convertFunction(all_options[show_list[graph_id]].option));
			}
		});
	  setTimeout(function(){make_pic(myChart,d);}
		, 5000);
}
$('#graph-hidden-1001').click(function () {
	graph_message= {
			'graph_name':'申请趋势图',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				},

			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	
  	var graph_id = $(this).attr('id').split('-')[2];
    var d = curr_num
  	var div_id = add_new_div(d)
 	var myChart = echarts.init(document.getElementById(div_id));
  	post_to_draw(myChart,graph_message,graph_id,d);
});

$('#graph-hidden-1002').click(function () {
	graph_message= {
			'graph_name':'授权趋势图',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20,
				},
				'axis':'x'
			},
			'constraints':[
			               {'type':'equal','key':'ls','value':2}
			               ],
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}

	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});

$('#graph-hidden-1003').click(function () {
	graph_message= {
			'graph_name':'授权趋势和授权趋势比较图',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				},

				
			},
			'branch':{
					'key':'ls',
					'label':['申请','授权'],
					'range':{
						'type':'hyperset',
						'value':[[0,1,2,3],2]
					},
					'name':'法律状态',

			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});
$('#graph-hidden-2001').click(function () {
	graph_message= {
			'graph_name':'各地专利申请量分布',
			'basis':{
				'key':'prc',//优先权国家
				'name':'优先权国家',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2002').click(function () {
	graph_message= {
			'graph_name':'各地专利申请年度申请趋势',
			'basis':{
				'key':'ap_year',//申请年
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				}
			},
			'branch':{
					'key':'prc',//优先权国家
					'name':'国家/地区',
					'label':'auto',
					'range':{
						'type':'auto',
						'value':10
					}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2003').click(function () {
		graph_message= {
			'graph_name':'各地专利申请分布',
			'basis':{
				'key':'ro',//受理局
				'name':'受理局',
				'range':{'type':'auto',
						'value':10}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2004').click(function () {
	graph_message= {
			'graph_name':'受理局的年度受理趋势',
			'basis':{
				'key':'ap_year',//申请年
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				},
				'axis':'x',
			},
			'branch':{
					'key':'ro',//受理局
					'name':'受理局',
					'label':'auto',
					'range':{
						'type':'auto',
						'value':10
					}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2005').click(function () {
	graph_message= {
			'graph_name':'5大技术来源国 与目标市场',
			'basis':{
				'key':'ro',//受理局
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':5
				},
				'axis':'x',
			},
			'branch':{
					'key':'prc',//优先权国家
					'name':'优先权国家',
					'label':'auto',
					'range':{
						'type':'auto',
						'value':5
					}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2006').click(function () {
	
	dataX = [];
  	valueY1 = [];
  	valueY2 = [];
  	valueY3 = [];
	$.ajax({
	type : 'GET',
	url : '/draw/graph/2006',
	//data : jsonda,
	cache: false,
	async:false,
	//contentType: "application/json; charset=utf-8",
	dataType : 'json',
	success : function(res) {
		yValue0 = res.yValue0;
		dataX = res.xAxis;
	},
	error : function(xml, err, throwInfo) {
		alert(err);
	}
	});
	var min=yValue0[0];
	var max=yValue0[0];
	for(var j=0;j<yValue0.length;j++){
		if(parseInt(yValue0[j])>parseInt(max)){
			max=yValue0[j];
		}
		if(parseInt(yValue0[j])<parseInt(min)){
			min=yValue0[j];
		}
	}
	
	for(var j=0;j<yValue0.length;j++){
		for(var i=j;i<yValue0.length;i++){
			if(parseInt(yValue0[i])>parseInt(yValue0[j])){
				var tmp=yValue0[j];
				yValue0[j]=yValue0[i];
				yValue0[i]=tmp;
				
				var tmp=dataX[j];
				dataX[j]=dataX[i];
				dataX[i]=tmp;
			}
		}
	}
	option = {
		    title : {
		        text: '',//'中国各省的专利申请量分布',
		        //subtext: '中国各省的专利申请量分布',
		        x:'center'
		    },
		    
		    tooltip : {
		        trigger: 'item'
		    },
		    /*legend: {
		        orient: 'vertical',
		        x:'left',
		        data:['专利申请量']
		    },*/
		    
		    //dataRange: {
		    visualMap: {
		        min: 0,
		        max: max,
		        x: 'left',
		        y: 'bottom',
		        //splitNumber: 2,
		        text:[max, 0],          
		        //calculable : true,
		        color:['red','#f0ffff'],
		        formatter : function(v) {
		            return parseInt(v);
		        }
		        //precision: 0,
		        //splitNumber: 1,
		        //range:{start:'0',end:'10'},			        
		    },
		    toolbox: {
		        show: true,
		        //orient : 'vertical',
		        //x: 'right',
		        //y: 'center',
		        feature : {
		            dataView : {show: true, readOnly: false},
		            saveAsImage : {show: true},
		            restore : {show: true},
		            //dataZoom: {show:true}
		       
		        }
		    },
		    series : [
		        {
		            name: '专利申请量',
		            type: 'map',
		            //center: [95, 40], 
		            map: 'china',
		            /*mapLocation: {
		                x: 'left'
		            },*/
		            roam: true,
		            zoom:1.2,
		            itemStyle:{
		                normal:{label:{show:true}},
		                emphasis:{label:{show:true}}
		            },
		            data:[
		               
		            ]
		        },
		    ]
		};
	for(var j=0;j<yValue0.length;j++){
			option.series[0].data.push({name: dataX[j],value: yValue0[j]});
	}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	draw_graph(myChart,option);
	setTimeout(function(){make_pic(myChart,d);}
	, 5000);
});  
$('#graph-hidden-2007').click(function () {
	graph_message= {
			'graph_name':'专利申请量各省份分布',
			'basis':{
				'key':'apr',//省份
				'name':'省市',
				'range':{'type':'auto',
						'value':20}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-2008').click(function () {
	graph_message= {
			'graph_name':'各省份的专利年度申请趋势',
			'basis':{
				'key':'ap_year',//申请年
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				},
				'axis':'x',
			},
			'branch':{
					'key':'apr',//省份
					'name':'省份',
					'label':'auto',
					'range':{
						'type':'auto',
						'value':10
					}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3001').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构专利申请量分布',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3002').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构专利申请趋势',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				},
				'axis':'x'
			},
			'branch':{
				'key':'ap',
				'name':'申请人',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10

				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3003').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的专利申请类型',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'pt',
				'name':'专利类型',
				'label':['发明','新型','外观设计'],
				'range':{
					'type':'hyperset',
					'value':['1','2','3']
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3004').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的专利法律状态',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3005').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构在5大受理局的专利申请分布',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':5
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3006').click(function () {
	graph_message= {
			'graph_name':'申请人在各国家/地区的专利申请分布',
			'basis':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':20
            	}
			},
			'branch':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':1
				}
			},
//			'constraints':[
//			               {'type':'equal','key':'ap','value':'xxxxx'}//选择某一申请人
//            ],
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3007').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的重点技术领域分布',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-3008').click(function () {
	graph_message= {
			'graph_name':'申请人在各重点技术领域的专利分布',
			'basis':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'branch':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':1
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
 
$('#graph-hidden-3009').click(function () {
	graph_message= {
			'graph_name':'申请人在各重点技术领域的专利布局对比',
			'basis':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'branch':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
}); 
$('#graph-hidden-4001').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构专利申请量分布',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4002').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构专利申请趋势',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				}
			},
			'branch':{
				'key':'inventor',
				'name':'发明人',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4003').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的专利申请类型',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'pt',
				'name':'专利类型',
				'label':['发明','新型','外观设计'],
				'range':{
					'type':'hyperset',
					'value':['1','2','3']
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4004').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的专利法律状态',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4005').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构在5大受理局的专利申请分布',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':5
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4006').click(function () {
	graph_message= {
			'graph_name':'发明人在各国家/地区的专利申请分布',
			'basis':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':20
            	}
			},
			'branch':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':1
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4007').click(function () {
	graph_message= {
			'graph_name':'各企业/研发机构的重点技术领域分布',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-4008').click(function () {
	graph_message= {
			'graph_name':'发明人在各重点技术领域的专利分布',
			'basis':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'branch':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':1
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
 
$('#graph-hidden-4009').click(function () {
	graph_message= {
			'graph_name':'发明人在各重点技术领域的专利布局对比',
			'basis':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':20
				}
			},
			'branch':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
}); 

$('#graph-hidden-4010').click(function () {
	graph_message= {
			'graph_name':'发明人外观设计分布',
			'basis':{
				'key':'lc',
				'name':'LOC外观设计分类号',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':1
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
}); 
$('#graph-hidden-5001').click(function () {
	graph_message= {
			'graph_name':'IPC分类排名',
			'basis':{
				'key':'ic',
				'name':'技术分类',
				'range':{
				    'type':'auto',
				    'value':20
				}

			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5002').click(function () {
	graph_message= {
			'graph_name':'IPC分类申请趋势',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				}
			},
			'branch':{
				'key':'ic',
				'name':'技术分类',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5003').click(function () {
	graph_message= {
			'graph_name':'主要技术来源国的IPC分类分布',
			'basis':{
				'key':'prc',
				'name':'优先权国'
			},
			'branch':{
				'key':'ic',
				'name':'技术分类',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5004').click(function () {
	graph_message= {
			'graph_name':'主要受理局的IPC分类分布',
			'basis':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':5
            	}
			},
			'branch':{
				'key':'ic',
				'name':'技术分类',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5005').click(function () {
	graph_message= {
			'graph_name':'LOC分类排名',
			'basis':{
				'key':'lc',
				'name':'技术分类',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5006').click(function () {
	graph_message= {
			'graph_name':'LOC分类申请趋势',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':inventor
				}
			},
			'branch':{
				'key':'lc',
				'name':'技术分类',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5007').click(function () {
	graph_message= {
			'graph_name':'专利技术生命周期',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'label':['1988~1990','1991~1993','1994~1996','1997~1999','2000~2002','2003~2005','2006~2008','2009~2011','2012~2014','2015~2017'],
				'range':{
		            'type':'hyperset',
		            'value':[[1988,1989,1990],[1991,1992,1993],[1994,1995,1996],[1997,1998,1999],[2000,2001,2002],[2003,2004,2005],[2006,2007,2008],[2009,2010,2011],[2012,2013,2014],[2015,2016,2017]]
		        }
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			},{
				'key':'applicant_count',
				'name':'申请人数量',
				'unit':'人'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5008').click(function () {
	graph_message= {
			'graph_name':'专利申请量对比',
			'basis':{
				'key':'br',
				'name':'细分技术',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
 
$('#graph-hidden-5009').click(function () {
	graph_message= {
			'graph_name':'专利申请趋势对比',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
					'type':'set',
					'value':date_set_20
				}
			},
			'branch':{
				'key':'br',
				'name':'细分技术',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
}); 

$('#graph-hidden-5010').click(function () {
	graph_message= {
			'graph_name':'技术来源国研发优势对比',
			'basis':{
				'key':'prc',
				'name':'优先权国家',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'br',
				'name':'细分技术',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
}); 
$('#graph-hidden-5011').click(function () {
	graph_message= {
			'graph_name':'各受理局专利申请对比',
			'basis':{
				'key':'ro',
				'name':'受理局',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'br',
				'name':'细分技术',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-5012').click(function () {
	graph_message= {
			'graph_name':'主要企业专利布局对比',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'br',
				'name':'细分技术',
				'label':'auto',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'target':[{
				'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6001').click(function () {
	graph_message= {
			'graph_name':'法律状态图',
			'basis':{
				'key':'ls',
				'name':'法律状态',
		        'label':['未授权','有效','已失效'],
		        'range':{
		            'type':'hyperset',
		            'value':[1,2,3]
		        }
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6002').click(function () {
	graph_message= {
			'graph_name':'专利申请法律状态年度分布',
			'basis':{
				'key':'ap_year',
				'name':'申请年',
				'range':{
                	'type':'set',
                	'value':date_set_20
                },
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6003').click(function () {
	graph_message= {
			'graph_name':'国家/地区专利申请法律状态',
			'basis':{
				'key':'prc',
				'name':'优先权国家',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}
			]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6004').click(function () {
	graph_message= {
			'graph_name':'申请人专利申请法律状态',
			'basis':{
				'key':'ap',
				'name':'申请人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6005').click(function () {
	graph_message= {
			'graph_name':'申请人专利申请法律状态',
			'basis':{
				'key':'inventor',
				'name':'发明人',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  
$('#graph-hidden-6006').click(function () {
	graph_message= {
			'graph_name':'技术IPC专利申请法律状态',
			'basis':{
				'key':'icm',
				'name':'ipc主分类号',
				'range':{
					'type':'auto',
					'value':10
				}
			},
			'branch':{
				'key':'ls',
				'name':'法律状态',
				'label':['未授权','有效','已失效'],
				'range':{
					'type':'hyperset',
					'value':[1,2,3]
				}
			},
			'target':[{
			    'key':'patent_count',
				'name':'专利数量',
				'unit':'件'
			}]
		}
	var graph_id = $(this).attr('id').split('-')[2];
	var d = curr_num
	var div_id = add_new_div(d)
	var myChart = echarts.init(document.getElementById(div_id));
	post_to_draw(myChart,graph_message,graph_id,d);
});  

});

function hoverDataText(param, basisName, targetName){
    var result = "";
    var xLabel = wrapTextInBox(param[0].name).replace(/[\r\n]/g, "<br/>");
    result += basisName+": "+xLabel;
    if (param.length >1){
        for (var i=0;i<param.length;i++){
            var color = param[i].color;
            result += "<br/><span style='color:"+color+"'>●  </span>";
            var yLabel = wrapTextInBox(param[i].seriesName).replace(/[\r\n]/g, "<br/>");
            var value = param[i].value;
            result += ""+yLabel+" ("+targetName+": "+value+")";
        }
    } else {
        value = param[0].value;
        result += "<br/>"+targetName+": "+value;
    }

    return result;
}

function hoverDataTextBubble(param, basisName, branchName, targetName){
    var result = "";
    var xLabel = wrapTextInBox(param[0].value[0]).replace(/[\r\n]/g, "<br/>");
    result += basisName+": "+xLabel;
    var seriesArray = new Array();
    for (var i=param.length-1;i>=0;i--){
        var color = param[i].color;
        result += "<br/><span style='color:"+color+"'>●  </span>";
        var yLabel = wrapTextInBox(param[i].seriesName).replace(/[\r\n]/g, "<br/>");
        var value = param[i].value[2];
        result += ""+yLabel+" ("+targetName+": "+value+")";
    }
    return result
}

function hoverDataText2Target(param, basisName, targetName1, targetName2){
    var result = "";
//    alert(param.data)
    result += basisName+": "+param.data[2]+"<br/>";
    result += targetName1+": "+param.data[0]+"<br/>";
    result += targetName2+": "+param.data[1];
    return result;
}

function process(key,value) {
    console.log(key + " : "+value);
}

function traverse(o,func) {
    for (var i in o) {
        if (o[i] !=null){
            if (typeof(o[i]) == "string"){
                if (o[i].indexOf("function") == 0){
                    o[i] = eval("("+o[i]+")");
                }
            }
        }

        if (o[i] !== null && typeof(o[i])=="object") {
            traverse(o[i],func);
        }
    }
}

function convertFunction(json){
    traverse(json, process);
	return json;
}

var WordWrap = function(text, fontsize, width) {
    var wordslength = function(text) {
        if (text == null) text = "";
        var len = text.length, wordslength = 0;
        for (var i = 0; i < len; i++) {
            if (text.charCodeAt(i) > 128) {
                wordslength += 2;
            } else {
                wordslength += 1;
            }
        }
        return wordslength;
    };

    var cutString=function(str, leng) {
        var len = str.length, tlen = len, nlen = 0;
        for (var x = 0; x < len; x++) {
            if (str.charCodeAt(x) > 128) {
                if (nlen + 2 < leng) {
                    nlen += 2;
                } else {
                    tlen = x+1;
                    break;
                }
            } else {
                if (nlen + 1 < leng) {
                    nlen += 1;
                } else {
                    tlen = x+1;
                    break;
                }
            }
        }
        return tlen;
    };

    var textperline = function(text,fontsize, width) {
        var lines=[];
        while(wordslength(text)>0){
            var len=Math.floor(width/(fontsize/1.8));
            var linewidth=cutString(text,len);
            lines.push(text.substr(0,linewidth));
            text=text.substr(linewidth);
        }
        return lines;
    };
    this.lines = textperline(text,fontsize,width);
    this.rows =this.lines.length;
};

function wrapText(text){
    return wrap(text, 1, 10);
}

function wrapTextInBox(text){
    return wrap(text, 1, 30);
}

function wrapTextInLegend(text){
    return wrap(text, 1, 20);
}

function wrap(text, a, b){
    var wordwrap = new WordWrap(text, a, b);
    var str = wordwrap.lines[0];
    for(var i=1,l=wordwrap.rows;i<l;i++){
        str = str + "\n"+ wordwrap.lines[i];
    }
    return str;
} 


